package com.lc.rongzecaifu.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;

import com.lc.rongzecaifu.MyApplication;
import com.lc.rongzecaifu.adapter.InvestDetailAdapter;
import com.lc.rongzecaifu.conn.JsonAccessToken;
import com.lc.rongzecaifu.conn.JsonInvestList;
import com.lc.rongzecaifu.rongzecaifu.R;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/4.
 */
public class InvestManageDetailRecyActivity extends BaseActivity {

    private RecyclerView recy_rv;

    private List<JsonInvestList.Info.ListContent> lists = new ArrayList<>();

    private InvestDetailAdapter adapter;

    private String getId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_investmanagedetail_recy);
        getId = getIntent().getStringExtra("id");

        Log.d(getId, "9999999999999999999999999");
        initView();
        getBankListAccessToken();
    }


    public void initView() {

        recy_rv = (RecyclerView) findViewById(R.id.recy_rv);

        LinearLayoutManager manager = new LinearLayoutManager(this);
        recy_rv.setLayoutManager(manager);

        recy_rv.setAdapter(adapter = new InvestDetailAdapter(this, lists));

    }

    private void getBankListAccessToken() {
        new JsonAccessToken("user/tendout_detial", new AsyCallBack<JsonAccessToken.Info>() {
            @Override
            public void onSuccess(String toast, int type, JsonAccessToken.Info info) throws Exception {
                if (info != null) {
                    if (!TextUtils.isEmpty(info.access_token)) {
                        initData(info.access_token);
                    } else {
                        UtilToast.show(InvestManageDetailRecyActivity.this, "安全验证失败！");
                    }
                }
            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
                UtilToast.show(InvestManageDetailRecyActivity.this, "安全验证失败！");
            }
        }).execute(this, true);

    }


    public void initData(String access_token) {
//        new AsyCallBack<JsonBanklist.Info>()
        new JsonInvestList(access_token, MyApplication.myPreferences.readUid(), getId, new AsyCallBack<JsonInvestList.Info>() {

            @Override
            public void onSuccess(String toast, int type, JsonInvestList.Info info) throws Exception {
                super.onSuccess(toast, type, info);

                lists.addAll(info.list);

                adapter.notifyDataSetChanged();

            }
        }).execute(InvestManageDetailRecyActivity.this, true);
    }


}
